const CommomUtil = require('../utils/CommomUtil');
const SessionUtil = require('../utils/SessionUtil');

const tag_dao = require('../dao/tag_dao');

/** 获取标签列表 */
module.exports.ql_tags = query_tag_list;
async function query_tag_list(ctx) {
    let { ty_id, ty_s_id, begin, plen } = CommomUtil.getReqData(ctx);
    let resData = {};
    if (CommomUtil.isEmpty(ty_id) || CommomUtil.isEmpty(ty_s_id)) {
        resData['ret'] = false;
        resData['msg'] = '参数不全!';
        return ctx.body = resData;
    }
    if (!(await SessionUtil.checkTySession(ty_id, ty_s_id))) {
        resData['ret'] = false;
        resData['msg'] = '请先登录!';
        return ctx.body = resData;
    }
    let tag_list = await tag_dao.query_tag_list(0, 50);
    if (tag_list.length < 1) {
        resData['tag_list'] = [];
        resData['ret'] = false;
        resData['msg'] = '暂无数据!';
        return ctx.body = resData;
    }
    resData['tag_list'] = tag_list;
    resData['ret'] = true;
    resData['msg'] = '查询成功!';
    return ctx.body = resData;
}